package aux;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.LinkedList;
import javax.swing.JLabel;

/**
 *
 * @author yan
 */
public class LabelButton extends JLabel{
    private Color normal,mouseover,click;
    private LinkedList<ActionListener> act= new LinkedList<ActionListener>();
    private String actioncommand;
    private int i;
    
    public LabelButton(String s) {
        super(s);
        normal = Color.BLACK;
        mouseover = Color.BLUE;
        click = Color.RED;
        addMouseListener(new Eventer());
        actioncommand = "";
        i=1;
    }
    
    public void addActionListener (ActionListener al) {
        act.add(al);
    }
    
    public void setActionCommand (String actcmd) {
        actioncommand = actcmd;
    }
    
    public void setMouseOverColor (Color c) {
        mouseover = c;
    }
    
    public void setNormalColor (Color c){
        normal = c;
    }
    
    public void setClickColor (Color c) {
        click = c;
    }
    
    private LabelButton getThis() {
        return this;
    }
    
    private class Eventer implements MouseListener {

        public void mouseClicked(MouseEvent e) {
            for(ActionListener al: act)
                al.actionPerformed(new ActionEvent(getThis(),i++,actioncommand));
        }

        public void mousePressed(MouseEvent e) {
            setForeground(click);
        }

        public void mouseReleased(MouseEvent e) {
            setForeground(normal);
        }

        public void mouseEntered(MouseEvent e) {
            setForeground(mouseover);
        }

        public void mouseExited(MouseEvent e) {
            setForeground(normal);
        }
        
    }
}
